﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>平台机构管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layui-form layuiadmin-card-header-auto">
                <div class="layui-input-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">启用状态：</label>
                        <div class="layui-input-block">
                            <select name="delFlag" id="delFlag" lay-filter="delFlag">
                                <option value="-1">全部</option>
                                <option value="0">已启用</option>
                                <option value="1">已停用</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-input-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select name="isAudit" id="isAudit" lay-filter="isAudit">
                                <option value="-1">全部</option>
                                <option value="0">未审核</option>
                                <option value="1">审核通过</option>
                                <option value="2">审核未通过</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-input-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">查询条件：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="search" type="text" name="search" placeholder="请输入机构名称、编号、信用代码" />
                        </div>
                    </div>
                </div>
                <div class="layui-input-inline">
                    <div class="layui-form-item">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-worker-get" id="btnSearch">
                            <i class="layui-icon layuiadmin-button-btn layui-icon-search"></i>查询
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table class="layui-table" id="gridWorkers" lay-filter="gridWorkers"></table>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element'], {
        data: {
            $layui: null,
            right: null,
            tablework: null,
        },
        pageload: function (right) {
            this.data.right = right;
            this.data.tablework = this.loadtableworker();
            this.initevent();
        },
        initevent() {
            var self = this;
            var table = layui.table;
            var form = layui.form;
            // 监听行工具事件
            table.on("tool(gridWorkers)", function (obj) {
                var data = obj.data;
                if (obj.event === "disable" || obj.event === "enable") {
                    self.stopworker(data);
                } else if (obj.event === "alter") {
                    self.alterworker(data);
                }
                else if (obj.event == "audit") {
                    //auditworker(data);
                }
                else if (obj.event == "initdata") {
                    //initdata(data);
                }
            });

            //查找
            form.on('submit(LAY-worker-get)', function (data) {
                self.data.tablework.reload({
                    where: {
                        status: data.field.delFlag,
                        isaudit: data.field.isAudit,
                        search: data.field.search
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
        },
        loadtableworker() {
            var table = layui.table;
            return table.render({
                elem: "#gridWorkers",
                headers: lobsterlayui.GetHeaderData(),
                where: {
                    status: $('#delFlag').val(),
                    isaudit: $('#isAudit').val(),
                    search: $('#search').val()
                },
                height: "full-120",
                cellMinWidth: 80, //全局定义常规单元格的最小宽度
                url: "/admin/v1/worker/GetWorkerData", //数据接口
                page: true, //开启分页
                loading: true,
                cols: [[ //表头
                    { field: "WorkId", width: "5%", title: "机构ID" },
                    { field: "WorkNo", width: "15%", title: "机构代码" },
                    { field: "WorkName", width: "15%", title: "机构名称" },
                    { field: "UnifiedSocialCreditCode", width: "15%", title: "统一社会信用代码" },
                    { field: "RegKey", width: "15%", title: "注册码" },
                    { field: "Contact", width: "10%", title: "联系人" },
                    { field: "ContactTel", width: "10%", title: "联系电话" },
                    { field: "IsAudit", width: "10%", title: "审核结果", templet: "#barAuditStates" },
                    { field: "States", width: "10%", title: "状态", templet: "#barRowStates" },
                    { field: "ExpiredDate", width: "10%", title: "过期时间", templet: "#ExpiredDateTpl" },
                    { field: "Memo", width: "10%", title: "备注" },
                    { field: "CreatedUserName", width: "10%", title: "创建人" },
                    { field: "CreatedTime", width: "10%", title: "创建时间" },
                    { field: "AuditUserName", width: "10%", title: "审核人" },
                    { field: "AuditTime", width: "10%", title: "审核时间", templet: "#AuditTimeTpl" },
                    { field: "AuditDesc", width: "10%", title: "审核备注" },
                    { title: "操作", width: "15%", align: 'center', toolbar: "#barRowWorkers", fixed: "right" }
                ]],
                parseData: function (res) {
                    return {
                        code: res.code,
                        msg: res.msg,
                        count: res.data.count,
                        data: res.data.workerList
                    }
                }
            });
        },
        stopworker(data) {
            // 启用停用机构
            var self = this;
            var confirm_msg = "";
            var status = 0;
            if (data.DelFlag == 0) {
                confirm_msg = "确认停用么?";
                status = 1;
            }
            else {
                confirm_msg = "确认启用么?";
                status = 0;
            }

            layer.confirm(confirm_msg, { icon: 3, title: "提示" },
                function (index) {

                    lobsterlayui.GET('/admin/v1/worker/StopWorker', { workid: data.WorkId, delflag: status }).then(data => {
                        layer.close(index);
                        self.data.tablework.reload();
                    })
                });
        },
        alterworker(data) {
            var self = this;
            var form = layui.form;
            // 修改机构
            layer.open({
                type: 1,
                title: "编辑机构信息",
                btn: ["保存", "取消"],
                btnAlign: "r",
                content: $('#dlg_alterworker').html(), //"workersform.html",
                area: ["100%", "100%"],
                maxmin: true,
                btn2: function (index, layero) {
                    $("#LAY-work-form-reset").trigger('click');
                }
                , cancel: function () {
                    $("#LAY-work-form-reset").trigger('click');
                },
                success: function (layero, index) {
                    var workid = data.WorkId;
                    lobsterlayui.GET('/admin/v1/worker/GetWorkerDetails', { workid: workid }).then(data => {
                        form.val('formWorkers', data['worker']);
                    });
                },
                yes: function (index, layero) {
                    var submit = $('#btnSubmit');
                    layui.form.on('submit(btnSubmit)', function (formdata) {
                        var field = formdata.field;
                        var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });

                        lobsterlayui.POST('/admin/v1/worker/SaveWorker', field).then(data => {
                            layer.msg("保存成功");
                            layer.close(index);
                            self.data.tablework.reload();
                        });

                    });
                    submit.trigger("click");
                    
                },
            });
        },
    });
</script>

<script type="text/html" id="barRowStates">
    {{# if(d.DelFlag==1){ }}
    <span style="color:red">{{d.States}}</span>
    {{# } else { }}
    <span>{{d.States}}</span>
    {{# } }}
</script>
<script type="text/html" id="AuditTimeTpl">
    {{#  if(d.AuditTime==null||layui.util.toDateString(new Date(d.AuditTime).getTime(), 'yyyy-MM-dd') == '1900-01-01'){ }}
    <span></span>
    {{#  } else { }}
    {{ d.AuditTime }}
    {{#  } }}
</script>
<script type="text/html" id="ExpiredDateTpl">
    {{#  if(d.ExpiredDate==null||layui.util.toDateString(new Date(d.ExpiredDate).getTime(), 'yyyy-MM-dd') == '1900-01-01'){ }}
    <span></span>
    {{#  } else { }}
    {{ d.ExpiredDate }}
    {{#  } }}
</script>
<script type="text/html" id="barAuditStates">
    {{# if(d.IsAudit==0){ }}
    <span>未审核</span>
    {{# } else if(d.IsAudit==1) { }}
    <span>审核通过</span>
    {{# } else if(d.IsAudit==2) { }}
    <span>审核未通过</span>
    {{# } }}
</script>
<script type="text/html" id="barRowWorkers">
    {{# if(d.IsAudit==0){ }}
    <a class="layui-btn layui-btn-xs" lay-event="audit"><i class="layui-icon layui-icon-edit"></i>审核</a>
    {{# } else if(d.IsAudit==1) { }}
    <a class="layui-btn layui-btn-xs" lay-event="alter"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    {{# if(d.DelFlag==0){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable"><i class="layui-icon layui-extend-stop"></i>停用</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable"><i class="layui-icon layui-icon-ok"></i>启用</a>
    {{# } }}
    {{# } }}
    {{# if(d.IsAudit==1 && d.DelFlag==0) { }}
    <a class="layui-btn layui-btn-xs" lay-event="initdata"><i class="layui-icon layui-icon-edit"></i>初始化</a>
    {{# } }}
</script>

<script type="text/html" id="dlg_alterworker">

    <div class="layui-fluid box">
        <form class="layui-form" lay-filter="formWorkers" id="formWorkers">
            <div class="layui-card">
                <div class="layui-card-body box" id="workdetail">
                    <div class="layui-row">
                        <div class="layui-hide">
                            <input type="text" id="txtWorkId" name="WorkId" value="0" />
                            <input type="text" id="txtDelFlag" name="DelFlag" value="0" />
                            <input type="text" id="ParentWorkId" name="ParentWorkId" value="0" />
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>机构名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="WorkName" id="txtWorkName" class="layui-input" required lay-verify="required" style="position:absolute;z-index:2" autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>机构标识</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" required lay-verify="required" id="txtWorkCode" name="WorkNo" maxlength="30" disabled />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12" id="divWorkMold">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>机构类型</label>
                                <div class="layui-input-block">
                                    <select id="txtWorkMold" name="WorkMold">
                                        <option value="0">医院</option>
                                        <option value="1">集团</option>
                                        <option value="2">区域</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>统一社会信用码</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" required lay-verify="required" id="txtUnifiedSocialCreditCode" name="UnifiedSocialCreditCode" maxlength="30" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>机构注册码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="RegKey" id="txtRegKey" class="layui-input" required lay-verify="required" style="position:absolute;z-index:2" autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="txtMemo" name="Memo" maxlength="500" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <input type="button" lay-submit lay-filter="btnSubmit" id="btnSubmit" value="保存">
                        <input type="reset" id="LAY-work-form-reset" value="重置">
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>